package com.example.xiaodu.yuejian12.Adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.xiaodu.yuejian12.Activity.ActivityDetailActivity;
import com.example.xiaodu.yuejian12.Activity.ShowDetailActivity;
import com.example.xiaodu.yuejian12.Bean.ShowBean;
import com.example.xiaodu.yuejian12.MeIP;
import com.example.xiaodu.yuejian12.MyViewHolder.ItemViewHolder;
import com.example.xiaodu.yuejian12.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by xiaodu on 2018/10/9.
 */
public class ShowAdapter extends RecyclerView.Adapter {
    private List<ShowBean> showBeanList;
    private MeIP ip=new MeIP();
    private String meIP=ip.getIP();

    public void setData(List<ShowBean> list){
        showBeanList=list;
        notifyDataSetChanged();
    }

    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        View itemView=inflater.inflate(R.layout.show_item,parent,false);
        ItemViewHolder viewHolder=new ItemViewHolder(itemView);
        return viewHolder;
    }

    public void onBindViewHolder(RecyclerView.ViewHolder holder ,int position){
        final ItemViewHolder viewHolder=(ItemViewHolder)holder;
        ShowBean ShowBean=showBeanList.get(position);

        String time=ShowBean.getStime();
        String title=ShowBean.getTitle();
        String pic=ShowBean.getSpicture();


        viewHolder.time.setText("晒图时间： "+time);
        viewHolder.title.setText("晒图标题： "+title);
        Picasso.with(viewHolder.imageView.getContext()).load(meIP+"/yuejian/public/static/show/"+pic).into(viewHolder.imageView);


        viewHolder.itemView.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                int pos = viewHolder.getLayoutPosition();
                Intent intent = new Intent(v.getContext(), ShowDetailActivity.class);
                intent.putExtra("showID", showBeanList.get(pos).getSid());
                v.getContext().startActivity(intent);
            }
            });

    }

    public  int getItemCount(){
        if (showBeanList!=null)
            return showBeanList.size();
        else
            return 0;
    }

}
